<template>
	<view class="messageBox">
		<view v-if="messageList.length>0" class="messageitem" v-for="(item,index) in messageList"
			@click="handleDetail(item)">
			<view class="item_top">
				<view class="item_top_left">
					<image class="icon" v-if="item.type == 1" src="@/static/image/xttz.png" mode=""></image>
					<image class="icon" v-if="item.type == 2" src="@/static/image/zyxx.png" mode=""></image>
					<image class="icon" v-if="item.type == 3" src="@/static/image/tj.png" mode=""></image>
					<image class="icon" v-if="item.type == 4" src="@/static/image/xttz.png" mode=""></image>
					<view class="" style="margin-left: 20rpx;">
						{{item.title}}
					</view>
				</view>
				<view class="time">
					{{item.created_at}}
				</view>
			</view>
			<view class="content">
				{{item.content}}
			</view>
			<view class="heng"></view>
			<view class="item_bottom">
				<view class="">
					查看详情
				</view>
				<image src="@/static/image/right.png" mode="" style="width: 40rpx;height: 40rpx;"></image>
			</view>
			<view v-if="item.is_read == 0" class="" style="position: absolute;right: 10rpx;top: 10rpx;">
				<u-badge :isDot="true" type="success" bgColor="#FF6F6F"></u-badge>
			</view>
		</view>
		
		<view class="" style="height: 100rpx;"></view>

		<view v-if="messageList.length==0" class="nullBox">
			<image src="../../static/image/nullimg.png" mode="" style="width: 148rpx;height: 148rpx;"></image>
			<view class="">
				暂无消息
			</view>
		</view>


	</view>
</template>

<script>
	import {
		getmessages,
		getmessagesdetail,
		userinfo
	} from "@/api/api.js"
	export default {
		data() {
			return {
				messageList: [],
				pageNum: 1,
			}
		},
		onLoad() {},
		onShow() {
			this.handlegetmessages()
			this.handleuserinfo()
		},
		onReachBottom() {
			this.pageNum++;
			this.handlegetmessages();
		},
		methods: {
			async handleuserinfo() {
				let res = await userinfo()
				// console.log("用户信息", res)
				if (res.data.memssage_count > 0) {
					uni.setTabBarBadge({
						index: 2,
						text: res.data.memssage_count.toString()
					})
				}


			},

			async handlegetmessages() {
				let res = await getmessages({
					page: this.pageNum,
					page_size: 10
				})
				// this.messageList = res.data.data
				if (res.data.data.length == 0) {
					uni.showToast({
						title: '暂无更多通知！',
						icon: "none",
						duration: 1500
					});
				} else {
					res.data.data.forEach((item, index) => {
						this.messageList.push(item)
					})
				}


				// console.log("消息", res)
			},
			async handleDetail(item) {
				// console.log("11111", item)
				if (item.type == 2 || item.type == 3) {
					uni.navigateTo({
						url: `../home/taskDetail?id=${item.jump_id}`
					})
					let res = await getmessagesdetail({
						id: item.id
					})
				} else {
					uni.navigateTo({
						url: `./tongzhiDetail?id=${item.id}`
					})
				}

			},
		}
	}
</script>

<style scoped lang="scss">
	.messageBox {
		.nullBox {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #AEB8C2;
			line-height: 28rpx;
			text-align: center;
			margin: 0 auto;
			margin-top: 200rpx;
		}

		.messageitem {
			width: 100%;
			padding: 30rpx;
			box-sizing: border-box;
			margin-bottom: 20rpx;
			background-color: #ffffff;
			position: relative;

			.item_top {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.item_top_left {
					display: flex;
					align-items: center;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #073062;
					line-height: 37rpx;

					.icon {
						width: 48rpx;
						height: 48rpx;
					}
				}

				.time {
					font-size: 24rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #CCCCCC;
					line-height: 28rpx;
				}
			}

			.content {
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #999996;
				line-height: 33rpx;
				margin-top: 38rpx;
			}

			.heng {
				width: 690rpx;
				height: 1rpx;
				background-color: #F6F6F6;
				margin-top: 48rpx;
			}

			.item_bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 20rpx;
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #073062;
				line-height: 33rpx;
			}
		}
	}
</style>